﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class DAL_MatHang
    {
        Connect cn = new Connect();
        public DataTable showmathang()
        {
            string sql = "select * from MatHang";
            DataTable dt = new DataTable();
            dt = cn.GetTable(sql);
            return dt;
        }
        public void insertmathang(string mmh, string tmh, string sl, string nsx, string gm, string gb, string mancc, string hinhanh)
        {
            string sql = "insert MatHang values('" + mmh + "',N'" + tmh + "','" + sl + "','" + nsx + "','" + gm + "',N'" + gb + "','" + mancc + "','" + hinhanh + "')";
            cn.Excutenonquery(sql);
        }
        public DataTable tkhangtheoma(string dk)
        {
            string sql = "select * from MatHang where MaMH LIKE N'%" + dk + "%'";
            DataTable dt = new DataTable();
            dt = cn.GetTable(sql);
            return dt;
        }
        public DataTable tkhangtheoten(string dk)
        {
            string sql = "select * from MatHang where TenMH LIKE N'%" + dk + "%'";
            DataTable dt = new DataTable();
            dt = cn.GetTable(sql);
            return dt;
        }
        public DataTable tkhangtheogia(string dk)
        {
            string sql = "select * from MatHang where GiaBan LIKE '%" + dk + "%'";
            DataTable dt = new DataTable();
            dt = cn.GetTable(sql);
            return dt;
        }
        public void deletemathang(string mmh)
        {
            string sql = "delete MatHang WHERE MaMH=N'" + mmh + "'";
            cn.Excutenonquery(sql);
        }
        public void suamathang(string mmh1, string mmh, string tmh, string sl, string nsx, string gm, string gb)
        {
            string sql = "UPDATE MatHang SET MaMH='" + mmh + "',TenMH=N'" + tmh + "',SoLuong='" + sl + "',NgaySX='" + nsx + "',GiaMua='" + gm + "',GiaBan='" + gb + "' where MaMH='" + mmh1 + "'";
            cn.Excutenonquery(sql);

        }
        public int Dangnhap(string user, string pass)
        {
            _Login log = new _Login();
            return log.Dangnhap(user, pass);
        }
    }
}
